package com.glowdayz.glowmee;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.glowdayz.common.ActivityManager;
import com.glowdayz.common.CDialog;
import com.glowdayz.common.DateTime;
import com.glowdayz.common.ImageDownloader;
import com.glowdayz.common.PatternChecker;
import com.glowdayz.common.XmlParser;
import com.glowdayz.model.AddItem;
import com.glowdayz.model.CommonBannerCMD;
import com.glowdayz.model.PouchCMD;
import com.glowdayz.model.PouchCommentCMD;
import com.glowdayz.model.ProductCMD;
import com.glowdayz.model.UserInfo;

public class ViewPouch extends Activity implements OnScrollListener, OnClickListener, OnItemClickListener {
	
	private ActivityManager am = ActivityManager.getInstance();
	
	ListView commentList = null;
	ArrayList<PouchCommentCMD> list = null;
	DataAdapter adapter = null;
	
	LinearLayout llHeader = null;
	LinearLayout llFooter = null;
	
	TextView pouchTitle = null, pouchText = null, nickName = null, userInfo = null, 
			pickCreate_date = null, brandCreate_date = null, adminNickName = null;
	ImageView userImg = null, brandImg = null;
	ViewFlipper flipper = null;
	LinearLayout pickLayout = null, brandPickLayout = null, productLayout = null, productInfoLayout = null;
	
	/********** 페이지 구현 **********/
	private int page = 1;						// 현재 페이지
	private final static int pageSize = 20;		// 한 페이지에 보일 수
	private int totalCount = 0;					// 전체 게시물 수
	
	int productTotal = 0, productCount = 0, paramIdProduct = 0, paramIdBrand = 0, paramIdRegister = 0;
	String paramProductTitle = null, paramBrandTitle = null;
	
	ArrayList<ProductCMD> pouchProductList = null;
	
	ImageView beforeBt = null, forwardBt = null;
	ImageView productImg = null;
	TextView productTitle = null, productBrand = null, productVolume = null, productPrice = null, productText = null;
	LinearLayout pouchCount = null;
	
	TextView wishListBt = null, commentBt = null;
	
	Bitmap bm2 = null;
	
	Dialog dialog = null;
	
	EditText pouchComment = null;
	ImageView addPouchCommentBt = null;
	
	String commentText = "";
	
	int bannerTotal = 0;
	int bannerSort = 0;
	// 터치 이벤트 발생 지점의 x좌표 저장
    float xAtDown;
    float xAtUp;
    float yAtDown;
    float yAtUp;
    
    LinearLayout bottomLayout = null;
    
    TextView textTitle = null;
    
    String productUrl = null;
    
    boolean isOk = false;
    boolean isAdd = false;
    
    LinearLayout bannerText = null;
	ImageView[] indexButtons;
	int currentIndex = 0;
	FrameLayout flipperLayout = null;
    
    CountDownTimer countDownTimer;
	Handler mHandler = new Handler();
	
	int paramId = 0;
	int recommendCount = 0;
	String userImgStr = null;
	
	private ViewPager mPager;
	String categoryValue = null;
    
	@SuppressLint("SimpleDateFormat")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_pouch);
		
		am.addActivity(this);
		
		Intent fromIntent = getIntent();
		paramId = fromIntent.getIntExtra("PARAM_paramId", 0);
		
		isAdd = fromIntent.getBooleanExtra("PARAM_isAdd", false);
		if (isAdd) {
			isOk = true;
		}
		
		ImageView backBt = (ImageView) findViewById(R.id.backBt);
		backBt.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN: {
                        ImageView view = (ImageView) v;
                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
                        view.invalidate();
                        break;
                    }
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL: {
                        ImageView view = (ImageView) v;
                        view.getDrawable().clearColorFilter();
                        view.invalidate();
                        break;
                    }
                }
                return false;
            }
        });
		backBt.setOnClickListener(new Button.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (isOk) {
					Intent intent = new Intent();
					setResult(Activity.RESULT_OK, intent);
					finish();
				} else {
					finish();
				}
				
			}
		});
		
		textTitle = (TextView) findViewById(R.id.textTitle);
		
		(new PouchWorker()).execute();
	}
	
	private class PagerAdapterClass extends PagerAdapter{
		
		private LayoutInflater mInflater;

		public PagerAdapterClass(Context c){
			super();
			mInflater = LayoutInflater.from(c);
		}
		
		@Override
		public int getCount() {
			return pouchProductList.size();
		}

		@Override
		public Object instantiateItem(View pager, int position) {
			View v = mInflater.inflate(R.layout.list_pouch_product, null);
			
			ProductCMD item = pouchProductList.get(position);
			
			productImg = (ImageView) v.findViewById(R.id.productImg);
			productTitle = (TextView) v.findViewById(R.id.productTitle);
			productBrand = (TextView) v.findViewById(R.id.productBrand);
			productVolume = (TextView) v.findViewById(R.id.productVolume);
			productPrice = (TextView) v.findViewById(R.id.productPrice);
			productText = (TextView) v.findViewById(R.id.productText);
			productLayout = (LinearLayout) v.findViewById(R.id.productLayout);
			
			beforeBt = (ImageView) v.findViewById(R.id.beforeBt);
			forwardBt = (ImageView) v.findViewById(R.id.forwardBt);
			beforeBt.setVisibility(View.INVISIBLE);
			forwardBt.setVisibility(View.INVISIBLE);
			
			/*if (pouchProductList.size()  < 2) {
				beforeBt.setVisibility(View.INVISIBLE);
				forwardBt.setVisibility(View.INVISIBLE);
			}
			
			if (position == 0) {
				beforeBt.setVisibility(View.INVISIBLE);
			}
			
			if (pouchProductList.size() - 1 == position) {
				forwardBt.setVisibility(View.INVISIBLE);
			}*/
			
			ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + item.getImage().trim(), productImg);
			productTitle.setText(item.getProductTitle());
			productBrand.setText(item.getIdBrandValue());
			productVolume.setText(item.getVolume());
			productPrice.setText(item.getPrice() + "원");
			productText.setText(item.getProductText().replace("\n", " "));
			
			productLayout.setOnTouchListener(new OnTouchListener() {
				@Override
				public boolean onTouch(View v, MotionEvent arg1) {
					v.setBackgroundResource(android.R.drawable.list_selector_background);
					return false;
				}
			});
			paramIdProduct = item.getIdProduct();
			paramProductTitle = item.getProductTitle();
			final int finalIdProduct = item.getIdProduct();
			final String finalProductTitle = item.getProductTitle();
			productLayout.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					Intent productIntent = new Intent(ViewPouch.this, ViewProduct.class);
					productIntent.putExtra("PARAM_id", finalIdProduct);
					productIntent.putExtra("PARAM_title", finalProductTitle);
					startActivity(productIntent);
				}
			});
			
			ImageView categoryImg = (ImageView) v.findViewById(R.id.pouchCategory);
			if (categoryValue.equals("이거샀어")) {
				categoryImg.setImageResource(R.drawable.pouch_cate1);
			} else if (categoryValue.equals("이거어때")) {
				categoryImg.setImageResource(R.drawable.pouch_cate2);
			} else if (categoryValue.equals("이거추천")) {
				categoryImg.setImageResource(R.drawable.pouch_cate3);
			} else if (categoryValue.equals("사고싶어")) {
				categoryImg.setImageResource(R.drawable.pouch_cate4);
			} else if (categoryValue.equals("아무거나")) {
				categoryImg.setImageResource(R.drawable.pouch_cate5);
			}
			
			/*beforeBt.setOnTouchListener(new OnTouchListener() {
	            @Override
	            public boolean onTouch(View v, MotionEvent event) {
	                switch (event.getAction()) {
	                    case MotionEvent.ACTION_DOWN: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
	                        view.invalidate();
	                        break;
	                    }
	                    case MotionEvent.ACTION_UP:
	                    case MotionEvent.ACTION_CANCEL: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().clearColorFilter();
	                        view.invalidate();
	                        break;
	                    }
	                }
	                return false;
	            }
	        });
			final int beforePosition = position - 1;
			beforeBt.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					mPager.setCurrentItem(beforePosition);
				}
			});
			forwardBt.setOnTouchListener(new OnTouchListener() {
	            @Override
	            public boolean onTouch(View v, MotionEvent event) {
	                switch (event.getAction()) {
	                    case MotionEvent.ACTION_DOWN: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
	                        view.invalidate();
	                        break;
	                    }
	                    case MotionEvent.ACTION_UP:
	                    case MotionEvent.ACTION_CANCEL: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().clearColorFilter();
	                        view.invalidate();
	                        break;
	                    }
	                }
	                return false;
	            }
	        });
			final int afterPosition = position + 1;
			forwardBt.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					mPager.setCurrentItem(afterPosition);
				}
			});*/
    		
    		((ViewPager)pager).addView(v, 0);
    		
    		return v; 
		}

		@Override
		public void destroyItem(View pager, int position, Object view) {	
			((ViewPager)pager).removeView((View)view);
		}
		
		@Override
		public boolean isViewFromObject(View pager, Object obj) {
			return pager == obj; 
		}

		@Override public void restoreState(Parcelable arg0, ClassLoader arg1) {}
		@Override public Parcelable saveState() { return null; }
		@Override public void startUpdate(View arg0) {}
		@Override public void finishUpdate(View arg0) {}
	}
	
	public class BannerWorker extends AsyncTask<Object, CommonBannerCMD, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/pouchBannerXml.do?idPouch=" + paramId;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();

				/** 읽은 내용을 담기 위한 변수 */
				int bannerType = 0;
				String bannerTitle = null;
				String image = null;
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("totalArticleCount")) {
							parser.next();
							bannerTotal = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("bannerType")) {
							parser.next();
							bannerType = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("bannerTitle")) {
							parser.next();
							bannerTitle = parser.getText();
						} else if (tag.equals("thumbnail")) {
							parser.next();
							image = parser.getText();
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("item")) {
							CommonBannerCMD item = new CommonBannerCMD(bannerType, bannerTitle, image);
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(CommonBannerCMD... param) {
			LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View vv = li.inflate(R.layout.list_banner_item, null);
			ImageView bannerImg = (ImageView) vv.findViewById(R.id.bannerImg);
			bannerImg.setScaleType(ImageView.ScaleType.FIT_XY);
			ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + param[0].getCreate_date().trim(), bannerImg);
			bannerSort++;
			
			//bannerText.setText(bannerSort + " / " + bannerTotal);
			flipper.addView(vv);
			final int bannerType = param[0].getBannerLinkType();
			final String bannerUrl = param[0].getBannerLinkCode();
			bannerImg.setOnTouchListener(new OnTouchListener() {
				
				@Override
				public boolean onTouch(View v, MotionEvent event) {
					
					if(event.getAction() == MotionEvent.ACTION_DOWN) {
						xAtDown = event.getX(); // 터치 시작지점 x좌표 저장
						yAtDown = event.getY();
						
						countDownTimer.cancel();
						mHandler.removeCallbacksAndMessages(null);
					} else if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
						xAtUp = event.getX(); 	// 터치 끝난지점 x좌표 저장
						yAtUp = event.getY();
						
						if (xAtUp < xAtDown && (xAtDown - xAtUp) > 10) {
							// 왼쪽 방향 에니메이션 지정
							flipper.setInAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_left_in));
					        flipper.setOutAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_left_out));
					        		
					        if (bannerTotal > 1) {
					        	 // 다음 view 보여줌
								flipper.showNext();
								currentIndex++;
								updateIndexes();
								
								if (bannerTotal > 1) {
									//flipper.startFlipping();
									countDownTimer.start();
								}
					        }
						} else if (xAtUp > xAtDown && (xAtUp - xAtDown) > 10) {
							// 오른쪽 방향 에니메이션 지정
							flipper.setInAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_right_in));
					        flipper.setOutAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_right_out));
					        
					        if (bannerTotal > 1) {
					        	// 전 view 보여줌
								flipper.showPrevious();
								currentIndex--;
								updateIndexes();
								
								if (bannerTotal > 1) {
									//flipper.startFlipping();
									countDownTimer.start();
								}
					        }	
						} else if ((yAtUp - yAtDown) < 10 && (yAtUp - yAtDown) > -10) {
							Intent intent = null;
							switch (bannerType) {
							case 13:
								intent = new Intent(Intent.ACTION_VIEW, Uri.parse(bannerUrl));
								startActivity(intent);
								break;
								
							case 14:
								intent = new Intent(ViewPouch.this, WebPage.class);
								intent.putExtra("PARAM_bannerUrl", bannerUrl);
								startActivity(intent);
								break;
								
							case 15:
								intent = new Intent(ViewPouch.this, AddPouch.class);
								startActivity(intent);
								break;
								
							case 16:
								if (PatternChecker.getInstance().isNum(bannerUrl)) {
									intent = new Intent(ViewPouch.this, ViewPouch.class);
									intent.putExtra("PARAM_paramId", Integer.parseInt(bannerUrl));
									startActivity(intent);
								}
								break;
								
							case 17:
								if (PatternChecker.getInstance().isNum(bannerUrl)) {
									intent = new Intent(ViewPouch.this, ViewProduct.class);
									intent.putExtra("PARAM_id", Integer.parseInt(bannerUrl));
									startActivity(intent);
								}
								break;
								
							case 18:
								if (PatternChecker.getInstance().isNum(bannerUrl)) {
									intent = new Intent(ViewPouch.this, ViewEvent.class);
									intent.putExtra("PARAM_id", Integer.parseInt(bannerUrl));
									startActivity(intent);
								}
								break;
								
							case 19:
								if (PatternChecker.getInstance().isNum(bannerUrl)) {
									intent = new Intent(ViewPouch.this, ViewNotice.class);
									intent.putExtra("PARAM_id", Integer.parseInt(bannerUrl));
									startActivity(intent);
								}
								break;
								
							case 20:
								if (PatternChecker.getInstance().isNum(bannerUrl)) {
									intent = new Intent(ViewPouch.this, ProfileHome.class);
									intent.putExtra("PARAM_id", Integer.parseInt(bannerUrl));
									startActivity(intent);
								}
								break;
							}
						} else if (bannerTotal > 1) {
							countDownTimer.start();
						}
					}
					return true;
				}
			});
		}

		@Override
		protected void onPostExecute(Object param) {
			if (bannerTotal > 1) {
				countDownTimer.start();
			} else if (bannerTotal == 1) {
				//flipper.stopFlipping();
			} else if (bannerTotal < 1) {
				flipper.setVisibility(View.GONE);
				flipperLayout.setVisibility(View.GONE);
			}
			
			indexButtons = new ImageView[bannerTotal];
			for (int i = 0; i < bannerTotal; i++) {
				indexButtons[i] = new ImageView(ViewPouch.this);
				if (i == currentIndex) {
					indexButtons[i].setImageResource(R.drawable.banner_on);
				} else {
					indexButtons[i].setImageResource(R.drawable.banner_off);
				}

				indexButtons[i].setPadding(10, 10, 10, 10);
				bannerText.addView(indexButtons[i]);
			}
			
			CDialog.hideLoading();
		}
		
		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new BannerWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	private void updateIndexes() {
		currentIndex = currentIndex % bannerTotal;
		if (currentIndex < 0) {
			currentIndex = bannerTotal + currentIndex;
		}
		for (int i=0; i<bannerTotal; i++) {
			if (i == currentIndex) {
				indexButtons[i].setImageResource(R.drawable.banner_on);
			} else {
				indexButtons[i].setImageResource(R.drawable.banner_off);
			}
		}
	}
	
	public class PouchWorker extends AsyncTask<Object, PouchCMD, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/viewPouchXml.do?id=" + paramId;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();

				/** 읽은 내용을 담기 위한 변수 */
				int idPouch = 0;
				String idPouchCategoryValue = null;
				int idBrand = 0;
				String idBrandValue = null;
				String pouchTitle = null;
				String pouchText = null;
				int editerPick = 0;
				String create_date = null;
				int idRegister = 0;
				String idRegisterValue = null;
				String userType = null;
				int birthYear = 0;
				String skinType = null;
				int productCount = 0;
				int recommendCount = 0;
				int commentCount = 0;
				String thumbnail = null;
				String user_thumbnail = null;
				String brand_thumbnail = null;
				
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("totalArticleCount")) {
							parser.next();
							totalCount = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idPouch")) {
							parser.next();
							idPouch = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idPouchCategoryValue")) {
							parser.next();
							idPouchCategoryValue = parser.getText();
							categoryValue = idPouchCategoryValue;
						} else if (tag.equals("idBrand")) {
							parser.next();
							idBrand = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idBrandValue")) {
							parser.next();
							idBrandValue = parser.getText();
						} else if (tag.equals("pouchTitle")) {
							parser.next();
							pouchTitle = parser.getText();
						} else if (tag.equals("pouchText")) {
							parser.next();
							pouchText = parser.getText();
						} else if (tag.equals("editerPick")) {
							parser.next();
							editerPick = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("create_date")) {
							parser.next();
							create_date = parser.getText();
						} else if (tag.equals("idRegister")) {
							parser.next();
							idRegister = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idRegisterValue")) {
							parser.next();
							idRegisterValue = parser.getText();
						} else if (tag.equals("userType")) {
							parser.next();
							userType = parser.getText();
						} else if (tag.equals("birthYear")) {
							parser.next();
							birthYear = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("skinType")) {
							parser.next();
							skinType = parser.getText();
						} else if (tag.equals("productCount")) {
							parser.next();
							productCount = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("recommendCount")) {
							parser.next();
							recommendCount = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("commentCount")) {
							parser.next();
							commentCount = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("thumbnail")) {
							parser.next();
							thumbnail = parser.getText();
						} else if (tag.equals("user_thumbnail")) {
							parser.next();
							user_thumbnail = parser.getText();
						} else if (tag.equals("brand_thumbnail")) {
							parser.next();
							brand_thumbnail = parser.getText();
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("item")) {
							PouchCMD item = new PouchCMD(idPouch, idRegister, idRegisterValue, userType, idPouchCategoryValue, 
									pouchTitle, pouchText, recommendCount, editerPick, create_date, thumbnail, user_thumbnail, brand_thumbnail, 
									productCount, commentCount, idBrand, idBrandValue, birthYear, skinType);
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(PouchCMD... param) {
			/*pouchText.setText(param[0].getPouchText());
			
			productUrl = getResources().getString(R.string.server_url) + "/glowmee/listPouchProductXml.do?id=" + param[0].getIdPouch();
			pouchCount.removeAllViews();*/
			
			final PouchCMD item = param[0];
			
			textTitle.setText(item.getPouchTitle());
			
			recommendCount = item.getRecommendCount();
			userImgStr = item.getUserImage();
			
			ImageView editBt = (ImageView) findViewById(R.id.okBt);
			editBt.setImageResource(R.drawable.top_edit);
			editBt.setVisibility(View.GONE);
			if (item.getIdRegister() == UserInfo.getInstance().getUSER_ID()) {
				/*DisplayMetrics dm =  getResources().getDisplayMetrics();
				
				int pixel1 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 43 , dm);
				int pixel2 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 83 , dm);
				textTitle.setPadding(pixel1, 0, pixel2, 0);
				
				editBt.setVisibility(View.VISIBLE);
				LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
				int pixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40 , dm);
				lp.setMargins(0, 0, pixel, 0);
				editBt.setLayoutParams(lp);*/
				editBt.setVisibility(View.VISIBLE);
				editBt.setOnTouchListener(new OnTouchListener() {
		            @Override
		            public boolean onTouch(View v, MotionEvent event) {
		                switch (event.getAction()) {
		                    case MotionEvent.ACTION_DOWN: {
		                        ImageView view = (ImageView) v;
		                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
		                        view.invalidate();
		                        break;
		                    }
		                    case MotionEvent.ACTION_UP:
		                    case MotionEvent.ACTION_CANCEL: {
		                        ImageView view = (ImageView) v;
		                        view.getDrawable().clearColorFilter();
		                        view.invalidate();
		                        break;
		                    }
		                }
		                return false;
		            }
		        });
				editBt.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						Intent intent = new Intent(ViewPouch.this, EditPouch.class);
						intent.putExtra("PARAM_id", item.getIdPouch());
						intent.putExtra("PARAM_category", item.getIdPouchCategoryValue());
						intent.putExtra("PARAM_title", item.getPouchTitle());
						intent.putExtra("PARAM_text", item.getPouchText());
						startActivityForResult(intent, 20);
					}
				});
			}
			
			wishListBt = (TextView) findViewById(R.id.wishListBt);
			wishListBt.setText("추천 " + item.getRecommendCount());
			commentBt = (TextView) findViewById(R.id.commentBt);
			wishListBt.setOnClickListener(ViewPouch.this);
			commentBt.setOnClickListener(ViewPouch.this);
			
			commentList = (ListView) findViewById(R.id.commentList);
			
			LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			llHeader = (LinearLayout) inflater.inflate(R.layout.inc_pouch, null);
			commentList.addHeaderView(llHeader);
			
			pouchTitle = (TextView) llHeader.findViewById(R.id.pouchTitle);
			pouchText = (TextView) llHeader.findViewById(R.id.pouchText);
			nickName = (TextView) llHeader.findViewById(R.id.nickName);
			userInfo = (TextView) llHeader.findViewById(R.id.userInfo);
			pickCreate_date = (TextView) llHeader.findViewById(R.id.pickCreate_date);
			brandCreate_date = (TextView) llHeader.findViewById(R.id.brandCreate_date);
			adminNickName = (TextView) llHeader.findViewById(R.id.adminNickName);
			
			userImg = (ImageView) llHeader.findViewById(R.id.userImg);
			brandImg = (ImageView) llHeader.findViewById(R.id.brandImg);
			pickLayout = (LinearLayout) llHeader.findViewById(R.id.pickLayout);
			brandPickLayout = (LinearLayout) llHeader.findViewById(R.id.brandPickLayout);
			//productLayout = (LinearLayout) llHeader.findViewById(R.id.productLayout);
			//productInfoLayout = (LinearLayout) llHeader.findViewById(R.id.productInfoLayout);
			
			bannerText = (LinearLayout) llHeader.findViewById(R.id.bannerText);
			flipperLayout = (FrameLayout) llHeader.findViewById(R.id.flipperLayout);
			flipper = (ViewFlipper) llHeader.findViewById(R.id.viewFlipper);
			// 왼쪽 에니메이션 설정
			flipper.setInAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_left_in));
			flipper.setOutAnimation(AnimationUtils.loadAnimation(ViewPouch.this, R.anim.push_left_out));
			        
			/*beforeBt = (ImageView) llHeader.findViewById(R.id.beforeBt);
			forwardBt = (ImageView) llHeader.findViewById(R.id.forwardBt);
			beforeBt.setOnTouchListener(new OnTouchListener() {
	            @Override
	            public boolean onTouch(View v, MotionEvent event) {
	                switch (event.getAction()) {
	                    case MotionEvent.ACTION_DOWN: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
	                        view.invalidate();
	                        break;
	                    }
	                    case MotionEvent.ACTION_UP:
	                    case MotionEvent.ACTION_CANCEL: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().clearColorFilter();
	                        view.invalidate();
	                        break;
	                    }
	                }
	                return false;
	            }
	        });
			forwardBt.setOnTouchListener(new OnTouchListener() {
	            @Override
	            public boolean onTouch(View v, MotionEvent event) {
	                switch (event.getAction()) {
	                    case MotionEvent.ACTION_DOWN: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
	                        view.invalidate();
	                        break;
	                    }
	                    case MotionEvent.ACTION_UP:
	                    case MotionEvent.ACTION_CANCEL: {
	                        ImageView view = (ImageView) v;
	                        view.getDrawable().clearColorFilter();
	                        view.invalidate();
	                        break;
	                    }
	                }
	                return false;
	            }
	        });
			
			productImg = (ImageView) llHeader.findViewById(R.id.productImg);
			
			productTitle = (TextView) llHeader.findViewById(R.id.productTitle);
			productBrand = (TextView) llHeader.findViewById(R.id.productBrand);
			productVolume = (TextView) llHeader.findViewById(R.id.productVolume);
			productPrice = (TextView) llHeader.findViewById(R.id.productPrice);
			productText = (TextView) llHeader.findViewById(R.id.productText);*/
			pouchCount = (LinearLayout) llHeader.findViewById(R.id.pouchCount);
			
			pouchTitle.setText(item.getPouchTitle());
			pouchText.setText(item.getPouchText());
			
			if (item.getUserType().equals("ADMIN") && item.getBrandImage().equals("null")) {
				userInfo.setVisibility(View.GONE);
				brandPickLayout.setVisibility(View.GONE);
				nickName.setText(item.getIdRegisterValue());
				
				try {
					Date dateTime = (new SimpleDateFormat("yyyyMMddHHmmss")).parse(item.getCreate_date().trim());
					String time = DateTime.getInstance().calculateTime(dateTime);
					if (time == null) {
						pickCreate_date.setText(DateTime.getInstance().getDateTimeString3(item.getCreate_date().trim()));
					} else {
						pickCreate_date.setText(time);
					}
					pickCreate_date.setTextSize(11);
				} catch (ParseException e) {
					e.printStackTrace();
				}
				
				/*pickLayout.setOnClickListener(ViewPouch.this);
				pickLayout.setOnTouchListener(new OnTouchListener() {
					@Override
					public boolean onTouch(View v, MotionEvent arg1) {
						v.setBackgroundResource(android.R.drawable.list_selector_background);
						return false;
					}
				});*/
				
				if (item.getEditerPick() == 1) {
					countDownTimer = new CountDownTimer(60 * 60 * 1000, 5 * 1000) {
						public void onTick(long millisUntilFinished) {
							mHandler.postDelayed(new Runnable() {
								@Override
								public void run() {
									flipper.showNext();
									currentIndex++;
									updateIndexes();
								}
							}, 5000); 
						}

						public void onFinish() {
						}
					};
					(new BannerWorker()).execute();
				} else {
					flipper.setVisibility(View.GONE);
					flipperLayout.setVisibility(View.GONE);
				}
			}
			
			if (item.getUserType().equals("ADMIN") && !item.getBrandImage().equals("null")) {
				userInfo.setVisibility(View.GONE);
				pickLayout.setVisibility(View.GONE);
				
				ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + item.getBrandImage().trim(), brandImg);
				
				try {
					Date dateTime = (new SimpleDateFormat("yyyyMMddHHmmss")).parse(item.getCreate_date().trim());
					String time = DateTime.getInstance().calculateTime(dateTime);
					if (time == null) {
						brandCreate_date.setText(DateTime.getInstance().getDateTimeString3(item.getCreate_date().trim()));
					} else {
						brandCreate_date.setText(time);
					}
					brandCreate_date.setTextSize(11);
				} catch (ParseException e) {
					e.printStackTrace();
				}
				
				brandPickLayout.setOnClickListener(ViewPouch.this);
				brandPickLayout.setOnTouchListener(new OnTouchListener() {
					@Override
					public boolean onTouch(View v, MotionEvent arg1) {
						v.setBackgroundResource(android.R.drawable.list_selector_background);
						return false;
					}
				});
				
				if (item.getEditerPick() == 1) {
					countDownTimer = new CountDownTimer(60 * 60 * 1000, 5 * 1000) {
						public void onTick(long millisUntilFinished) {
							mHandler.postDelayed(new Runnable() {
								@Override
								public void run() {
									flipper.showNext();
									currentIndex++;
									updateIndexes();
								}
							}, 5000); 
						}

						public void onFinish() {
						}
					};
					(new BannerWorker()).execute();
				} else {
					flipper.setVisibility(View.GONE);
					flipperLayout.setVisibility(View.GONE);
				}
			}
			
			if (item.getUserType().equals("USER")) {
				adminNickName.setVisibility(View.GONE);
				brandPickLayout.setVisibility(View.GONE);
				flipper.setVisibility(View.GONE);
				flipperLayout.setVisibility(View.GONE);
				nickName.setText(item.getIdRegisterValue());
				String info = null;
				if (item.getBirthYear() > 0) {
					int age = Calendar.getInstance().get(Calendar.YEAR) - item.getBirthYear() + 1;
					info = age + "세";
				}
				if (!item.getSkinType().equals("null")) {
					if (info == null) {
						info = item.getSkinType();
					} else {
						info += "," + item.getSkinType();
					}
				}
				userInfo.setText(info);
				
				(new UserImageWorker()).execute();
				
				try {
					Date dateTime = (new SimpleDateFormat("yyyyMMddHHmmss")).parse(item.getCreate_date().trim());
					String time = DateTime.getInstance().calculateTime(dateTime);
					if (time == null) {
						pickCreate_date.setText(DateTime.getInstance().getDateTimeString3(item.getCreate_date().trim()));
					} else {
						pickCreate_date.setText(time);
					}
					pickCreate_date.setTextSize(11);
				} catch (ParseException e) {
					e.printStackTrace();
				}
				
				paramIdRegister = item.getIdRegister();
				
				pickLayout.setOnClickListener(ViewPouch.this);
				pickLayout.setOnTouchListener(new OnTouchListener() {
					@Override
					public boolean onTouch(View v, MotionEvent arg1) {
						v.setBackgroundResource(android.R.drawable.list_selector_background);
						return false;
					}
				});
			}
			
			LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			llFooter = (LinearLayout) li.inflate(R.layout.list_footer, null);
			llFooter.setVisibility(View.GONE);
			// 리스트뷰에 추가
			commentList.addFooterView(llFooter);
			commentList.setOnScrollListener(ViewPouch.this);
			
			list = new ArrayList<PouchCommentCMD>();
			adapter = new DataAdapter(ViewPouch.this, list);
			commentList.setAdapter(adapter);
			commentList.setOnItemClickListener(ViewPouch.this);
			
			pouchProductList = new ArrayList<ProductCMD>();
			
			productUrl = getResources().getString(R.string.server_url) + "/glowmee/listPouchProductXml.do?id=" + item.getIdPouch();
			
			(new PouchProductListWorker()).execute();
			
			(new CommentWorker()).execute();
			
			paramIdBrand = item.getIdBrand();
			paramBrandTitle = item.getIdBrandValue();
			
			/*ImageView categoryImg = (ImageView) findViewById(R.id.pouchCategory);
			if (item.getIdPouchCategoryValue().equals("이거샀어")) {
				categoryImg.setImageResource(R.drawable.pouch_cate1);
			} else if (item.getIdPouchCategoryValue().equals("이거어때")) {
				categoryImg.setImageResource(R.drawable.pouch_cate2);
			} else if (item.getIdPouchCategoryValue().equals("이거추천")) {
				categoryImg.setImageResource(R.drawable.pouch_cate3);
			} else if (item.getIdPouchCategoryValue().equals("사고싶어")) {
				categoryImg.setImageResource(R.drawable.pouch_cate4);
			} else if (item.getIdPouchCategoryValue().equals("아무거나")) {
				categoryImg.setImageResource(R.drawable.pouch_cate5);
			}*/
			
			bottomLayout = (LinearLayout) findViewById(R.id.bottomLayout);
			
			(new CheckWorker()).execute();
		}

		@Override
		protected void onPostExecute(Object param) {
			CDialog.hideLoading();
		}
		
		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new PouchWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	public class UserImageWorker extends AsyncTask<Object, ProductCMD, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			if (userImgStr != null) {
				try {
					URL url = new URL(getResources().getString(R.string.server_url) + userImgStr.trim()); 
					URLConnection conn = url.openConnection(); 
					conn.connect(); 
					BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); 
					bm2 = BitmapFactory.decodeStream(bis); 
					bis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(ProductCMD... param) {
		}

		@Override
		protected void onPostExecute(Object param) {
			if (bm2 == null) {
				userImg.setImageResource(R.drawable.profileimg);
			} else {
				userImg.setImageBitmap(bm2);
			}
			CDialog.hideLoading();
		}
		
		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
		}
	}
	
	public class PouchProductListWorker extends AsyncTask<Object, ProductCMD, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(productUrl);
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();

				/** 읽은 내용을 담기 위한 변수 */
				int idProduct = 0;
				String productTitle = null;
				String idBrandValue = null;
				String volume = null;
				int price = 0;
				String productText = null;
				String thumbnail = null;
				
				
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("totalArticleCount")) {
							parser.next();
							productTotal = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idProduct")) {
							parser.next();
							idProduct = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("productTitle")) {
							parser.next();
							productTitle = parser.getText();
						} else if (tag.equals("idBrandValue")) {
							parser.next();
							idBrandValue = parser.getText();
						} else if (tag.equals("volume")) {
							parser.next();
							volume = parser.getText();
						} else if (tag.equals("price")) {
							parser.next();
							price = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("productText")) {
							parser.next();
							productText = parser.getText();
						} else if (tag.equals("thumbnail")) {
							parser.next();
							thumbnail = parser.getText();
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("item")) {
							ProductCMD item = new ProductCMD(idProduct, idBrandValue, productTitle, volume, price, productText, thumbnail);
							pouchProductList.add(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(ProductCMD... param) {
		}

		@Override
		protected void onPostExecute(Object param) {
			/*beforeBt.setVisibility(View.INVISIBLE);
			forwardBt.setVisibility(View.INVISIBLE);
			
			if (productTotal > 1) {
				forwardBt.setVisibility(View.VISIBLE);
			}
			
			if (productTotal > 0) {
				ProductCMD item = pouchProductList.get(productCount);
				
				productTitle.setText(item.getProductTitle());
				productBrand.setText(item.getIdBrandValue());
				productVolume.setText(item.getVolume());
				productPrice.setText(item.getPrice() + "원");
				productText.setText(item.getProductText().replace("\n", " "));
				
				if (item.getIdProduct() == 1) {
					productInfoLayout.setVisibility(View.GONE);
				}
				
				ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + item.getImage().trim(), productImg);
				
				forwardBt.setOnClickListener(ViewPouch.this);
				productLayout.setOnClickListener(ViewPouch.this);
				productLayout.setOnTouchListener(new OnTouchListener() {
					@Override
					public boolean onTouch(View v, MotionEvent arg1) {
						v.setBackgroundResource(android.R.drawable.list_selector_background);
						return false;
					}
				});
				
				for (int j=0; j<productTotal; j++) {
					ImageView temp = new ImageView(ViewPouch.this);
					
					if (j == productCount) {
						temp.setImageResource(R.drawable.banner_on);
					} else {
						temp.setImageResource(R.drawable.banner_off);
					}
					
					temp.setPadding(7, 0, 7, 0);
					pouchCount.addView(temp);
				}
				
				paramIdProduct = item.getIdProduct();
				paramProductTitle = item.getProductTitle();
			} else {
				productLayout.setVisibility(View.GONE);
			}*/
			
			for (int j=0; j<productTotal; j++) {
				ImageView temp = new ImageView(ViewPouch.this);
				
				if (j == productCount) {
					temp.setImageResource(R.drawable.banner_on);
				} else {
					temp.setImageResource(R.drawable.banner_off);
				}
				
				temp.setPadding(7, 0, 7, 0);
				pouchCount.addView(temp);
			}
			
			mPager = (ViewPager) llHeader.findViewById(R.id.pager);
			mPager.setAdapter(new PagerAdapterClass(getApplicationContext()));
			//((ViewPagerIndicator) llHeader.findViewById(R.id.viewpager_indicator)).setViewPager(mPager);
			mPager.setOnPageChangeListener(new OnPageChangeListener() {
				
				@Override
				public void onPageSelected(int arg0) {
					pouchCount.removeAllViews();
					for (int j=0; j<pouchProductList.size(); j++) {
						ImageView temp = new ImageView(ViewPouch.this);
						
						if (j == arg0) {
							temp.setImageResource(R.drawable.banner_on);
						} else {
							temp.setImageResource(R.drawable.banner_off);
						}
						
						temp.setPadding(7, 0, 7, 0);
						pouchCount.addView(temp);
					}
				}
				
				@Override
				public void onPageScrolled(int arg0, float arg1, int arg2) {
				}
				
				@Override
				public void onPageScrollStateChanged(int arg0) {
				}
			});
			
			CDialog.hideLoading();
		}
		
		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new PouchProductListWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	public class DataAdapter extends ArrayAdapter<PouchCommentCMD> {
		private LayoutInflater inflater = null;

		// 생성자. 파라미터에 전달되는 List의 제너릭스 선언에 주의한다.
		public DataAdapter(Context context, List<PouchCommentCMD> objects) {
			super(context, 0, objects);
			inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}

		// ArrayList에 할당된 각 항목을 하나씩 추출하여 list_item.xml에 표현시키는 메서드
		// 이 메서드는 ListView에 의해서 호출된다.
		@SuppressLint("SimpleDateFormat")
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			/** 모든 컴포넌트의 최상위 클래스 */
			View view = null;

			// 데이터를 저장할 View 선언. view 객체는 "list_item.xml"파일을 의미한다.
			if (convertView == null) {
				view = inflater.inflate(R.layout.list_comment_item, null);
			} else {
				view = convertView;
			}

			// 하나의 데이터 항목을 추출한다.
			PouchCommentCMD item = getItem(position);

			// 추출한 데이터가 존재한다면 "list_item.xml"안의 컨트롤들을 추출하여 처리한다.
			if (item != null) {
				LinearLayout rootLayout = (LinearLayout) view.findViewById(R.id.rootLayout);
				rootLayout.setOnTouchListener(new OnTouchListener() {
					@Override
					public boolean onTouch(View v, MotionEvent arg1) {
						v.setBackgroundResource(android.R.drawable.list_selector_background);
						return false;
					}
				});
				
				LinearLayout commentLayout = (LinearLayout) view.findViewById(R.id.commentLayout);
				commentLayout.setBackgroundResource(R.drawable.box_review);
				
				ImageView userImg2 = (ImageView) view.findViewById(R.id.userImg);
				
				TextView commentText2 = (TextView) view.findViewById(R.id.commentText);
				TextView userInfo2 = (TextView) view.findViewById(R.id.userInfo);
				TextView create_date2 = (TextView) view.findViewById(R.id.create_date);
				
				commentText2.setText(item.getPouchComment());
				
				if (item.getSkinType().equals("null") && item.getBirthYear() != 0) {
					int age = Calendar.getInstance().get(Calendar.YEAR) - item.getBirthYear() + 1;
					userInfo2.setText(item.getIdRegisterValue() + " (" + age + "세" + ")");
				} else if (!item.getSkinType().equals("null") && item.getBirthYear() == 0) {
					userInfo2.setText(item.getIdRegisterValue() + " (" + item.getSkinType() + ")");
				} else if (!item.getSkinType().equals("null") && item.getBirthYear() != 0) {
					int age = Calendar.getInstance().get(Calendar.YEAR) - item.getBirthYear() + 1;
					userInfo2.setText(item.getIdRegisterValue() + " (" + age + "세/" + item.getSkinType() + ")");
				} else if (item.getSkinType().equals("null") && item.getBirthYear() == 0) {
					userInfo2.setText(item.getIdRegisterValue());
				}
				
				try {
					Date date = (new SimpleDateFormat("yyyyMMddHHmmss")).parse(item.getCreate_date().trim());
					String time = DateTime.getInstance().calculateTime(date);
					if (time == null) {
						create_date2.setText(DateTime.getInstance().getDateTimeString3(item.getCreate_date().trim()));
					} else {
						create_date2.setText(time);
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
				
				if (item.getBm() == null) {
					userImg2.setImageResource(R.drawable.profileimg);
				} else {
					userImg2.setImageBitmap(item.getBm());
				}
				
			}
			return view;
		}
	}
	
	public class CommentWorker extends AsyncTask<Object, PouchCommentCMD, Object> {
		@Override
		protected void onPreExecute() {
			llFooter.setVisibility(View.VISIBLE);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/listPouchCommentXml.do?" +
					"page=" + page + "&count=" + pageSize + "&id=" + paramId;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();

				/** 읽은 내용을 담기 위한 변수 */
				int idPouchComment = 0;
				int idRegister = 0;
				String idRegisterValue = null;
				int birthYear = 0;
				String skinType = null;
				String pouchComment = null;
				String create_date = null;
				String thumbnail = null;
				
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("totalArticleCount")) {
							parser.next();
							totalCount = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idPouchComment")) {
							parser.next();
							idPouchComment = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idRegister")) {
							parser.next();
							idRegister = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("idRegisterValue")) {
							parser.next();
							idRegisterValue = parser.getText();
						} else if (tag.equals("birthYear")) {
							parser.next();
							birthYear = Integer.parseInt(parser.getText().trim());
						} else if (tag.equals("skinType")) {
							parser.next();
							skinType = parser.getText();
						} else if (tag.equals("pouchComment")) {
							parser.next();
							pouchComment = parser.getText();
						} else if (tag.equals("create_date")) {
							parser.next();
							create_date = parser.getText();
						} else if (tag.equals("thumbnail")) {
							parser.next();
							thumbnail = parser.getText();
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("item")) {
							Bitmap bm = null;
							if (thumbnail != null) {
								try {
									URL url2 = new URL(getResources().getString(R.string.server_url) + thumbnail.trim()); 
									URLConnection conn = url2.openConnection(); 
									conn.connect(); 
									BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); 
									bm = BitmapFactory.decodeStream(bis); 
									bis.close();
								} catch (IOException e) {
									e.printStackTrace();
								}
							}
							
							PouchCommentCMD item = new PouchCommentCMD(
									idPouchComment, idRegister, idRegisterValue, pouchComment, create_date, thumbnail, birthYear, skinType, bm);
							
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(PouchCommentCMD... param) {
			adapter.add(param[0]);
		}

		@Override
		protected void onPostExecute(Object param) {
			commentBt.setText("댓글 " + totalCount);
			llFooter.setVisibility(View.GONE);
		}
		
		@Override
		protected void onCancelled() {
			llFooter.setVisibility(View.GONE);
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new CommentWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	// 화면에 리스트의 마지막 아이템이 보여지는 체크
	boolean lastItemVisibleFlag = false;
	
	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		lastItemVisibleFlag = (totalItemCount > 0) && (firstVisibleItem + visibleItemCount >= totalItemCount);
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && lastItemVisibleFlag) {
			int pageCount = ((totalCount -1) / pageSize) + 1;
			if (pageCount > 0 && page < pageCount) {
				page++;
				(new CommentWorker()).execute();
			}
		}
	}

	@Override
	public void onClick(View v) {
		//ProductCMD item = null;
		switch (v.getId()) {
		/*case R.id.beforeBt:
			productCount--;
			item = pouchProductList.get(productCount);
			
			productTitle.setText(item.getProductTitle());
			productBrand.setText(item.getIdBrandValue());
			productVolume.setText(item.getVolume());
			productPrice.setText(item.getPrice() + "원");
			productText.setText(item.getProductText().replace("\n", " "));
			//pouchCount.setText((productCount + 1) + " / " + productTotal);
			
			pouchCount.removeAllViews();
			for (int j=0; j<productTotal; j++) {
				ImageView temp = new ImageView(ViewPouch.this);
				
				if (j == productCount) {
					temp.setImageResource(R.drawable.banner_on);
				} else {
					temp.setImageResource(R.drawable.banner_off);
				}
				
				temp.setPadding(7, 0, 7, 0);
				pouchCount.addView(temp);
			}
			
			if (item.getIdProduct() == 1) {
				productInfoLayout.setVisibility(View.GONE);
			}
			
			ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + item.getImage().trim(), productImg);
			
			if (productCount == 0) {
				beforeBt.setVisibility(View.INVISIBLE);
			}
			forwardBt.setVisibility(View.VISIBLE);
			
			paramIdProduct = item.getIdProduct();
			paramProductTitle = item.getProductTitle();
			break;
			
		case R.id.forwardBt:
			productCount++;
			item = pouchProductList.get(productCount);
			
			productTitle.setText(item.getProductTitle());
			productBrand.setText(item.getIdBrandValue());
			productVolume.setText(item.getVolume());
			productPrice.setText(item.getPrice() + "원");
			productText.setText(item.getProductText().replace("\n", " "));
			//pouchCount.setText((productCount + 1) + " / " + productTotal);
			
			pouchCount.removeAllViews();
			for (int j=0; j<productTotal; j++) {
				ImageView temp = new ImageView(ViewPouch.this);
				
				if (j == productCount) {
					temp.setImageResource(R.drawable.banner_on);
				} else {
					temp.setImageResource(R.drawable.banner_off);
				}
				
				temp.setPadding(7, 0, 7, 0);
				pouchCount.addView(temp);
			}
			
			if (item.getIdProduct() == 1) {
				productInfoLayout.setVisibility(View.GONE);
			}
			
			ImageDownloader.getInstance().download(getResources().getString(R.string.server_url) + item.getImage().trim(), productImg);
			
			beforeBt.setVisibility(View.VISIBLE);
			beforeBt.setOnClickListener(ViewPouch.this);
			
			if (productCount + 1 == productTotal) {
				forwardBt.setVisibility(View.INVISIBLE);
			}
			
			paramIdProduct = item.getIdProduct();
			paramProductTitle = item.getProductTitle();
			break;
			
		case R.id.productLayout:
			if (paramIdProduct != 1) {
				Intent productIntent = new Intent(this, ViewProduct.class);
				productIntent.putExtra("PARAM_id", paramIdProduct);
				productIntent.putExtra("PARAM_title", paramProductTitle);
				startActivity(productIntent);
			}
			break;*/
			
		case R.id.brandPickLayout:
			Intent brandIntent = new Intent(this, ListBrandProduct.class);
			brandIntent.putExtra("PARAM_id", paramIdBrand);
			brandIntent.putExtra("PARAM_title", paramBrandTitle);
			startActivity(brandIntent);
			break;
			
		case R.id.pickLayout:
			if (paramIdRegister > 0) {
				Intent pickIntent = new Intent(this, ProfileHome.class);
				pickIntent.putExtra("PARAM_id", paramIdRegister);
				startActivity(pickIntent);
			} else {
				Intent pickIntent = new Intent(this, ListPick.class);
				pickIntent.putExtra("PARAM_type", "에디터픽");
				startActivity(pickIntent);
			}
			break;
			
		case R.id.wishListBt:
			if (UserInfo.getInstance().getUSER_ID() == 0) {
				AlertDialog.Builder confirm = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog));
				confirm.setTitle("로그인 안내");
				confirm.setMessage("로그인 이후에 서비스 이용이 가능합니다.");
				confirm.setCancelable(false);
				confirm.setPositiveButton("확인", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(ViewPouch.this, Login.class);
						intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
						startActivity(intent);
						return;
					}
				});
				confirm.create();
				confirm.show();
			} else {
				(new AddWorker()).execute();
			}
			break;
			
		case R.id.commentBt:
			if (UserInfo.getInstance().getUSER_ID() == 0) {
				AlertDialog.Builder confirm = new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light_Dialog));
				confirm.setTitle("로그인 안내");
				confirm.setMessage("로그인 이후에 서비스 이용이 가능합니다.");
				confirm.setCancelable(false);
				confirm.setPositiveButton("확인", new DialogInterface.OnClickListener() {
					
					@Override
					public void onClick(DialogInterface dialog, int which) {
						Intent intent = new Intent(ViewPouch.this, Login.class);
						intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
						startActivity(intent);
						return;
					}
				});
				confirm.create();
				confirm.show();
			} else {
				View popupView = View.inflate(this, R.layout.inc_add_comment, null);
				
				dialog = new Dialog(this);
				dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
				dialog.setContentView(popupView);
				dialog.show();
				
				Display display = getWindowManager().getDefaultDisplay();
			    Point size = new Point();
			    display.getSize(size);
				
				WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
				dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
				dialog.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
				lp.dimAmount = 0.7f;
				lp.gravity = Gravity.BOTTOM;
				lp.width = size.x;
				dialog.getWindow().setAttributes(lp);
				
				pouchComment = (EditText) popupView.findViewById(R.id.pouchComment);
				addPouchCommentBt = (ImageView) popupView.findViewById(R.id.addPouchCommentBt);
				addPouchCommentBt.setOnTouchListener(new OnTouchListener() {
		            @Override
		            public boolean onTouch(View v, MotionEvent event) {
		                switch (event.getAction()) {
		                    case MotionEvent.ACTION_DOWN: {
		                        ImageView view = (ImageView) v;
		                        view.getDrawable().setColorFilter(0x77000000,PorterDuff.Mode.SRC_ATOP);
		                        view.invalidate();
		                        break;
		                    }
		                    case MotionEvent.ACTION_UP:
		                    case MotionEvent.ACTION_CANCEL: {
		                        ImageView view = (ImageView) v;
		                        view.getDrawable().clearColorFilter();
		                        view.invalidate();
		                        break;
		                    }
		                }
		                return false;
		            }
		        });
				addPouchCommentBt.setOnClickListener(this);
			}
			break;
			
		case R.id.addPouchCommentBt:
			commentText = pouchComment.getText().toString().trim();
			
			if (commentText.equals("")) {
				Toast.makeText(this, "댓글 내용을 입력하세요.", Toast.LENGTH_SHORT).show();
				return;
			}
			
			(new AddCommentWorker()).execute();
			break;
			
		case R.id.okBt:
			AlertDialog.Builder temp = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			temp.setMessage("준비중입니다.");
			temp.setCancelable(false);
			temp.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
				}
			});
			temp.create();
			temp.show();
			break;
		}
		
	}
	
	public class AddWorker extends AsyncTask<Object, AddItem, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/addWishPouchXml.do?idRegister=" + UserInfo.getInstance().getUSER_ID()
					+ "&idPouch=" + paramId;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			// 통신 실패시 예외처리
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();
				
				/** 읽은 내용을 담기 위한 변수 */
				String rt = null;
				String rtmsg = null;
				int seq = 0;
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("rt")) {
							parser.next();
							rt = parser.getText();
						} else if (tag.equals("rtmsg")) {
							parser.next();
							rtmsg = parser.getText();
						} else if (tag.equals("seq")) {
							parser.next();
							seq = Integer.parseInt(parser.getText().trim());
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("JSPglowmee")) {
							AddItem item = new AddItem(rt, rtmsg, seq);
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(AddItem... param) {
			
			if (param[0].getRt().equals("SUCCESS")) {
				AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
				alert.setTitle("추천 성공");
				alert.setMessage(param[0].getRtmsg());
				alert.setCancelable(false);
				alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						bottomLayout.setBackgroundResource(R.drawable.button_pick_all_over);
						wishListBt.setText("추천 " + (recommendCount + 1));
					}
				});
				alert.create();
				alert.show();
			} else {
				AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
				alert.setTitle("추천 실패");
				alert.setMessage(param[0].getRtmsg());
				alert.setCancelable(false);
				alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
					}
				});
				alert.create();
				alert.show();
			}
			
		}

		@Override
		protected void onPostExecute(Object param) {
			CDialog.hideLoading();
		}

		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new AddWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	public class AddCommentWorker extends AsyncTask<Object, AddItem, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/addPouchCommentXml.do?idRegister=" + UserInfo.getInstance().getUSER_ID()
					+ "&idPouch=" + paramId + "&comment=" + commentText + "&writer=" + paramIdRegister;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			// 통신 실패시 예외처리
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();
				
				/** 읽은 내용을 담기 위한 변수 */
				String rt = null;
				String rtmsg = null;
				int seq = 0;
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("rt")) {
							parser.next();
							rt = parser.getText();
						} else if (tag.equals("rtmsg")) {
							parser.next();
							rtmsg = parser.getText();
						} else if (tag.equals("seq")) {
							parser.next();
							seq = Integer.parseInt(parser.getText().trim());
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("JSPglowmee")) {
							AddItem item = new AddItem(rt, rtmsg, seq);
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(AddItem... param) {
			
			if (param[0].getRt().equals("SUCCESS")) {
				AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
				alert.setTitle("등록 성공");
				alert.setMessage(param[0].getRtmsg());
				alert.setCancelable(false);
				alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						adapter.clear();
						(new CommentWorker()).execute();
					}
				});
				alert.create();
				alert.show();
			} else {
				AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
				alert.setTitle("등록 실패");
				alert.setMessage(param[0].getRtmsg());
				alert.setCancelable(false);
				alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
					}
				});
				alert.create();
				alert.show();
			}
			
		}

		@Override
		protected void onPostExecute(Object param) {
			CDialog.hideLoading();
		}

		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new AddCommentWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}
	
	public class CheckWorker extends AsyncTask<Object, AddItem, Object> {
		@Override
		protected void onPreExecute() {
			CDialog.showLoading(ViewPouch.this);
		}

		@Override
		protected Object doInBackground(Object... params) {
			Object result = null;
			
			String url = getResources().getString(R.string.server_url) + "/glowmee/checkWishPouchXml.do?idRegister=" + UserInfo.getInstance().getUSER_ID()
					+ "&idPouch=" + paramId;
			
			XmlPullParser parser = XmlParser.getInstance().getParser(url);
			// 통신 실패시 예외처리
			if (parser == null) {
				this.cancel(true);
				return null;
			}
			
			try {
				String tag = null;
				int type = parser.getEventType();
				
				/** 읽은 내용을 담기 위한 변수 */
				String rt = null;
				String rtmsg = null;
				int seq = 0;
				// 파싱 처리를 위한 반복 시작
				while (type != XmlPullParser.END_DOCUMENT) {
					// 읽은 태그의 이름
					tag = parser.getName();

					// 현재 읽고 있는 태그의 종류별로 분기
					switch (type) {
					case XmlPullParser.START_TAG:
						/** 원하는 종류의 시작태그를 만났을 때, 값을 추출 */
						if (tag.equals("rt")) {
							parser.next();
							rt = parser.getText();
						} else if (tag.equals("rtmsg")) {
							parser.next();
							rtmsg = parser.getText();
						} else if (tag.equals("seq")) {
							parser.next();
							seq = Integer.parseInt(parser.getText().trim());
						}
						
						break;

					case XmlPullParser.END_TAG:
						
						if (tag.equals("JSPglowmee")) {
							AddItem item = new AddItem(rt, rtmsg, seq);
							publishProgress(item);
						}
						break;
					}

					// 다음 태그로 이동하고, 상태값을 변경
					type = parser.next();
				}

			} catch (XmlPullParserException e) {
				System.out.println("파서 생성 실패 >> " + e.toString());
			} catch (IOException e) {
				System.out.println("파서 읽기 실패 >> " + e.toString());
			}
			
			return result;
		}

		@Override
		protected void onProgressUpdate(AddItem... param) {
			if (param[0].getRt().equals("SUCCESS")) {
				bottomLayout.setBackgroundResource(R.drawable.button_pick_all_over);
			}
		}

		@Override
		protected void onPostExecute(Object param) {
			CDialog.hideLoading();
		}

		@Override
		protected void onCancelled() {
			CDialog.hideLoading();
			AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(ViewPouch.this, android.R.style.Theme_Holo_Light_Dialog));
			alert.setMessage("일시적인 통신에러입니다.");
			alert.setCancelable(false);
			alert.setPositiveButton("다시 시도", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					(new CheckWorker()).execute();
				}
			});
			alert.setNegativeButton("뒤로 가기", new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					finish();
				}
			});
			alert.create();
			alert.show();
		}
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		if (arg2 > 0) {
			PouchCommentCMD select = adapter.getItem(arg2 - 1);
			Intent intent = new Intent(this, ProfileHome.class);
			intent.putExtra("PARAM_id", select.getIdRegister());
			startActivity(intent);
		}
	}
	
	@Override
	public void onBackPressed() {
		if (isOk) {
			Intent intent = new Intent();
			setResult(Activity.RESULT_OK, intent);
			finish();
		} else {
			finish();
		}
	}
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		//super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == Activity.RESULT_OK) {
			if (requestCode == 20) {
				int type = data.getExtras().getInt("PARAM_type", 0);
				if (type == 1) {
					isOk = true;
					Intent intent = new Intent();
					setResult(Activity.RESULT_OK, intent);
					finish();
				} else if (type == 2) {
					Intent intent = new Intent();
					setResult(Activity.RESULT_OK, intent);
					finish();
				}
			}
			
		}
	}
	
    @Override
	protected void onDestroy() {
		super.onDestroy();
		am.removeActivity(this);
	}
	

}
